//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Priority
private alias 1 : PRIORITY_ACTIVE

private alias 114 : LEFTLIMIT

private alias Object.Value0 : Object.Timer
private alias Object.Value1 : Object.RightLimit
private alias Object.Value2 : Object.ScrollPos

private alias Object.Value5 : Object.LeftLight
private alias Object.Value6 : Object.RightLight
private alias Object.Value7 : Object.LeftDoor
private alias Object.Value8 : Object.RightDoor

private alias Object.Value9 : Object.LDoorSlide
private alias Object.Value10 : Object.RDoorSlide

private alias Object.Value11 : Object.OfficeAngle


private alias Object.Value12: Object.MiddleDoor
private alias Object.Value13 : Object.MDoorSlide


private alias Object.Value15 : Object.UsingMask
private alias Object.Value16 : Object.RButtonXPos
private alias Object.Value17 : Object.RightButtonPos
private alias Object.Value18 : Object.PowerTimer	
private alias Object.Value19 : Object.TouchTimer	//ayo
private alias Object.Value20 : Fan.FrameTimer
private alias Object.Value21 : Fan.Frame

private alias Object.Value22 : Object.RightSide
private alias Object.Value23 : Object.Flash
private alias Object.Value24 : Object.TableContainer
private alias Object.Value25 : Object.OuttaPower

public table OfficeFlash
	32, 64, 96, 64
end table


private alias object[10].state : Freddy.State
private alias object[11].state : Bonnie.State
private alias object[12].state : Chica.State
private alias object[13].state : Foxy.State
private alias object[14].state : Endo.State	//he doesnt actually appear here but 
private alias object[15].state : GoldenFreddy.State	//he doesnt actually appear here but 
private alias object[16].state : Puppet.State	//he doesnt actually appear here but 
private alias object[17].state : Springtrap.State

private alias object[18].state : WitheredFreddy.State
private alias object[19].state : WitheredBonnie.State
private alias object[20].state : WitheredChica.State
private alias object[21].state : WitheredFoxy.State

private alias object[22].state : BalloonBoy.State
private alias object[23].state : JJ.State

private alias object[24].state : ToyFreddy.State
private alias object[25].state : ToyBonnie.State
private alias object[26].state : ToyChica.State
private alias object[27].state : Mangle.State

private alias object[28].state : ShadowFreddy.State
private alias object[29].state : ShadowBonnie.State



private alias object[10].value4 : Freddy.AI
private alias object[11].value4 : Bonnie.AI
private alias object[12].value4 : Chica.AI
private alias object[13].value4 : Foxy.AI
private alias object[14].value4 : Endo.AI
private alias object[15].value4 : GoldenFreddy.AI
private alias object[16].value4 : Puppet.AI
private alias object[17].value4 : Springtrap.AI

private alias object[18].value4 : WitheredFreddy.AI
private alias object[19].value4 : WitheredBonnie.AI
private alias object[20].value4 : WitheredChica.AI
private alias object[21].value4 : WitheredFoxy.AI

private alias object[22].value4 : BalloonBoy.AI
private alias object[23].value4 : JJ.AI

private alias object[24].value4 : ToyFreddy.AI
private alias object[25].value4 : ToyBonnie.AI
private alias object[26].value4 : ToyChica.AI
private alias object[27].value4 : Mangle.AI

private alias object[28].value4 : ShadowFreddy.AI
private alias object[29].value4 : ShadowBonnie.AI



public alias saveRAM[6010] : custom.freddy
public alias saveRAM[6011] : custom.bonnie
public alias saveRAM[6012] : custom.chica
public alias saveRAM[6013] : custom.foxy
public alias saveRAM[6014] : custom.golden
public alias saveRAM[6015] : custom.endo
public alias saveRAM[6016] : custom.puppet
public alias saveRAM[6017] : custom.ballboy
public alias saveRAM[6018] : custom.jirl
public alias saveRAM[6019] : custom.springtrap
public alias saveRAM[6020] : custom.shadowfred
public alias saveRAM[6021] : custom.shadowbon
public alias saveRAM[6022] : custom.toyfreddy
public alias saveRAM[6023] : custom.toybonnie
public alias saveRAM[6024] : custom.toychica
public alias saveRAM[6025] : custom.mango
public alias saveRAM[6026] : custom.withfreddy
public alias saveRAM[6027] : custom.withbonnie
public alias saveRAM[6028] : custom.withchica
public alias saveRAM[6029] : custom.withfoxy

public alias saveram[1987] : saved.Mouse

public value LeftDoorClosed = 0;
public value RightDoorClosed = 0;
public value MiddleDoorClosed = 0;
public value UseMouse = 0;
public value OfficePower = 100;
public value CameraEnabled = 0;
public value PowerUsage = 1;
public value MaskMode = 0;
public value MaskEquipped = 0;
public value NightWon = 0;

public value LDoorLocked= 0;
public value RDoorLocked = 0;
public value MDoorLocked = 0;

public value LWindowScare= 0;
public value RWindowScare = 0;

public value PlayerJumpscared = 0;
public value ForcePull = 0;
public value OfficeScary = 0;

public value FlashlightOn = 0;
public value FlashLocked = 0;

reserve function Office_LeftSide
reserve function Office_RightSide
reserve function Office_Controls
reserve function Office_PowerDraining
reserve function Office_MiddleDoor
reserve function Night_AI

function Night_AI
	switch stage.actnum
	case 1
		if stage.minutes < 2
			Freddy.AI = -1
			Bonnie.AI = -1
			Chica.AI = -1
			Foxy.AI = -1
			Endo.AI = -1
			GoldenFreddy.AI = -1
			Puppet.AI = -1
			Springtrap.AI = -1
		else
			Freddy.AI = 1
			Bonnie.AI = 3
			Chica.AI = 3
			Foxy.AI = 2
			Endo.AI = 1
			GoldenFreddy.AI = 0
			Puppet.AI = -1
			Springtrap.AI = -1
		end if

		BalloonBoy.AI = -1
		JJ.AI = -1
		WitheredFreddy.AI	= -1
		WitheredBonnie.AI	= -1
		WitheredChica.AI	= -1
		WitheredFoxy.AI 	= -1

		ToyFreddy.AI	= -1
		ToyBonnie.AI	= -1
		ToyChica.AI		= -1
		Mangle.AI		= -1				

		ShadowFreddy.AI		= -1
		ShadowBonnie.AI		= -1
	break
	case 2
		Freddy.AI = 2
		Bonnie.AI = 4
		Chica.AI = 4
		Foxy.AI = 3
		Endo.AI = 3
		GoldenFreddy.AI = 1
		Puppet.AI = 1
		Springtrap.AI = 0
		BalloonBoy.AI = 1
		JJ.AI = 1


		WitheredFreddy.AI	= -1
		WitheredBonnie.AI	= -1
		WitheredChica.AI	= -1
		WitheredFoxy.AI 	= -1	

		ToyFreddy.AI	= -1
		ToyBonnie.AI	= -1
		ToyChica.AI		= -1
		Mangle.AI		= -1		

		ShadowFreddy.AI		= -1
		ShadowBonnie.AI		= -1
	break
	case 3
		Freddy.AI = 4
		Bonnie.AI = 6
		Chica.AI = 6
		Foxy.AI = 5
		Endo.AI = 4
		GoldenFreddy.AI = 3
		Puppet.AI = 1
		Springtrap.AI = 1


		BalloonBoy.AI = 3
		JJ.AI = 3

		WitheredFreddy.AI	= -1
		WitheredBonnie.AI	= -1
		WitheredChica.AI	= -1
		WitheredFoxy.AI 	= -1	

		ToyFreddy.AI	= -1
		ToyBonnie.AI	= -1
		ToyChica.AI		= -1
		Mangle.AI		= -1				
	break
	case 4
		Freddy.AI = 6
		Bonnie.AI = 8
		Chica.AI = 8
		Foxy.AI = 8
		Endo.AI = 8
		GoldenFreddy.AI = 5
		Puppet.AI = 1
		Springtrap.AI = 6

		BalloonBoy.AI = 6
		JJ.AI = 6

		WitheredFreddy.AI	= -1
		WitheredBonnie.AI	= -1
		WitheredChica.AI	= -1
		WitheredFoxy.AI 	= -1			

		ToyFreddy.AI	= -1
		ToyBonnie.AI	= -1
		ToyChica.AI		= -1
		Mangle.AI		= -1		

		ShadowFreddy.AI		= 0
		ShadowBonnie.AI		= 0
	break	
	case 5
		Freddy.AI = 10
		Bonnie.AI = 12
		Chica.AI = 12
		Foxy.AI = 12
		Endo.AI = 15
		GoldenFreddy.AI = 6
		Puppet.AI = 1
		Springtrap.AI = 8

		BalloonBoy.AI = 7
		JJ.AI = 7

		WitheredFreddy.AI	= -1
		WitheredBonnie.AI	= -1
		WitheredChica.AI	= -1
		WitheredFoxy.AI 	= -1

		ToyFreddy.AI	= -1
		ToyBonnie.AI	= -1
		ToyChica.AI		= -1
		Mangle.AI		= -1			

		ShadowFreddy.AI		= 1
		ShadowBonnie.AI		= 1				
	break		
	case 6
		Freddy.AI = 15
		Bonnie.AI = 17
		Chica.AI = 17
		Foxy.AI = 17
		Endo.AI = 12
		GoldenFreddy.AI = 17
		Puppet.AI = 1
		Springtrap.AI = 10

		BalloonBoy.AI = 10
		JJ.AI = 10

		WitheredFreddy.AI	= -1
		WitheredBonnie.AI	= -1
		WitheredChica.AI	= -1
		WitheredFoxy.AI 	= -1		

		ToyFreddy.AI	= -1
		ToyBonnie.AI	= -1
		ToyChica.AI		= -1
		Mangle.AI		= -1		

		ShadowFreddy.AI		= 5
		ShadowBonnie.AI		= 5	
	break		
	case 7
		Freddy.AI = custom.freddy
		Bonnie.AI = custom.bonnie
		Chica.AI = custom.chica
		Foxy.AI = custom.foxy
		Endo.AI = custom.endo
		GoldenFreddy.AI = custom.golden
		Puppet.AI = custom.puppet
		Springtrap.AI = custom.springtrap

		BalloonBoy.AI = custom.ballboy
		JJ.AI = custom.jirl

		WitheredFreddy.AI	= custom.withfreddy
		WitheredBonnie.AI	= custom.withbonnie
		WitheredChica.AI	= custom.withchica
		WitheredFoxy.AI 	= custom.withfoxy

		ToyFreddy.AI	= custom.toyfreddy
		ToyBonnie.AI	= custom.toybonnie
		ToyChica.AI		= custom.toychica
		Mangle.AI		= custom.mango

		ShadowFreddy.AI		= custom.shadowfred
		ShadowBonnie.AI		= custom.shadowbon
	break		
	end switch	
end function


function Office_MiddleDoor
	DrawSpriteScreenXY(33, Object.ScrollPos, 60)	//door
	if Object.MiddleDoor == 1	//open
		DrawSpriteScreenXY(34, Object.ScrollPos, 60)	//door
		if Object.MDoorSlide < 51
			Object.MDoorSlide += 8
		else
			Object.MDoorSlide = 51
		end if
		DrawSpriteScreenXY(32, Object.ScrollPos, Object.MDoorSlide)	//door
	else
		if Object.MDoorSlide > 0
			Object.MDoorSlide -= 8
		else
			Object.MDoorSlide = 0
		end if	
		DrawSpriteScreenXY(32, Object.ScrollPos, Object.MDoorSlide)	//door

	end if	

	DrawSpriteScreenXY(31, Object.ScrollPos, -32)
end function

function Office_PowerDraining

	Object.PowerTimer++

	if Object.PowerTimer == 600	
		//lose power

		//coded like this so it stacks, im sure theres a better way to do this	
	

		CheckEqual(CameraEnabled, 1)
		temp2 = checkResult
		if temp2 == 1
			OfficePower--
		end if

		CheckEqual(Object.LeftDoor, 1)
		temp2 = checkResult
		if temp2 == 1
			OfficePower--
		end if

		CheckEqual(Object.RightDoor, 1)
		temp2 = checkResult
		if temp2 == 1
			OfficePower--
		end if

		CheckEqual(Object.MiddleDoor, 1)
		temp2 = checkResult
		if temp2 == 1
			OfficePower--
		end if		

	
		CheckEqual(FlashlightOn, 1)
		temp2 = checkResult
		if temp2 == 1
			OfficePower--
		end if
		

		Object.PowerTimer = 0	
	end if

end function

function Office_Controls
if OfficePower > 0
	if inputpress.buttona == 1
		if LDoorLocked == 0
			if Object.LeftDoor == 0
				Object.LeftDoor = 1
				LeftDoorClosed = 1
				PowerUsage++
				PlaySfx(SfxName[Door], 0)	
			else
				if Object.LeftDoor == 1
					PowerUsage--
					LeftDoorClosed = 0
					Object.LeftDoor = 0
					LeftDoorClosed = 0
					PlaySfx(SfxName[Door], 0)	
				end if		
			end if	
		else
			PlaySfx(SfxName[Error], 0)	
		end if	
	end if

	if inputpress.buttonC == 1
		if RDoorLocked == 0
			if Object.RightDoor == 0
				Object.RightDoor = 1
				RightDoorClosed = 1
				PowerUsage++
				PlaySfx(SfxName[Door], 0)	
			else
				if Object.RightDoor == 1
					PowerUsage--
					RightDoorClosed = 0
					Object.RightDoor = 0
					PlaySfx(SfxName[Door], 0)	
				end if		
			end if	
		else
			PlaySfx(SfxName[Error], 0)	
		end if	
	end if		


	CheckEqual(CameraEnabled, 0)
	temp1 = checkResult
	CheckEqual(FlashLocked, 0)
	temp1 &= checkResult		
	if temp1 == 1
		if inputdown.buttonZ == 1
			if FlashlightOn == 0
				FlashlightOn = 1
				PowerUsage++
				PlaySfx(SfxName[Flashlight], 0)	
			end if
		else	
			if FlashlightOn == 1
				PowerUsage--
				PlaySfx(SfxName[Flashlight], 0)	
				FlashlightOn = 0
			end if		
		end if
	else
		if FlashlightOn == 1
			PowerUsage--
			PlaySfx(SfxName[Flashlight], 0)	
			FlashlightOn = 0
		end if	
	end if

	if inputpress.buttonX == 1
		if MDoorLocked == 0
			if Object.MiddleDoor == 0
				Object.MiddleDoor = 1
				MiddleDoorClosed = 1
				PowerUsage++
				PlaySfx(SfxName[Door], 0)	
			else
				if Object.MiddleDoor == 1
					PowerUsage--
					MiddleDoorClosed = 0
					Object.MiddleDoor = 0
					PlaySfx(SfxName[Door], 0)	
				end if		
			end if	
		else
			PlaySfx(SfxName[Error], 0)	
		end if	
	end if


	if Object.LeftLight == 1
		Object.RightLight = 0
	end if
	if Object.RightLight == 1
		Object.LeftLight = 0
	end if
end if
end function

function Office_RightSide
	DrawSpriteScreenXY(18, Object.ScrollPos, 0)



	if Object.RightLight == 1
		if PlayerJumpscared == 1
			StopSfx(SfxName[Hum])
		else
			PlaySfx(SfxName[Hum], 1)	
		end if	
			
		//left door button
		DrawSpriteScreenXY(21, Object.ScrollPos, 0)

		DrawSpriteScreenXY(20, Object.ScrollPos, 0)
	end if	

	
//	if Freddy.State == 15
//		//FREDDY AT THE DOOR!!!
//		DrawSpriteScreenXY(26, Object.ScrollPos, 0)
//	end if



	if Object.RightDoor == 1	//open
		DrawSpriteScreenXY(19, Object.ScrollPos, 0) //left door button on
		if Object.RDoorSlide < 312
			Object.RDoorSlide += 18
		else
			Object.RDoorSlide = 312
		end if
		DrawSpriteScreenXY(23, Object.ScrollPos, Object.RDoorSlide)	//door
	else
		if Object.RDoorSlide > 0
			Object.RDoorSlide -= 18
		else
			Object.RDoorSlide = 0
		end if	
		DrawSpriteScreenXY(23, Object.ScrollPos, Object.RDoorSlide)	//door
	end if	

	//frame
	DrawSpriteScreenXY(22, Object.ScrollPos, 0)

end function

function Office_LeftSide

	//LEFT SIDE
	//left door button
	DrawSpriteScreenXY(12, Object.ScrollPos, 0)


	if Object.LeftLight == 1
		if PlayerJumpscared == 1
			StopSfx(SfxName[Hum])
		else
			PlaySfx(SfxName[Hum], 1)	
		end if		
		//left door button
		DrawSpriteScreenXY(15, Object.ScrollPos, 0)
		DrawSpriteScreenXY(14, Object.ScrollPos, 0)
	end if

	



	if Object.LeftDoor == 1	//open
		DrawSpriteScreenXY(13, Object.ScrollPos, 0) //left door button on
		if Object.LDoorSlide < 312
			Object.LDoorSlide += 18
		else
			Object.LDoorSlide = 312
		end if
		DrawSpriteScreenXY(17, Object.ScrollPos, Object.LDoorSlide)	//door
	else
		if Object.LDoorSlide > 0
			Object.LDoorSlide -= 18
		else
			Object.LDoorSlide = 0
		end if	
		DrawSpriteScreenXY(17, Object.ScrollPos, Object.LDoorSlide)	//door
	end if	

	//frame
	DrawSpriteScreenXY(16, Object.ScrollPos, 1)
end function

event ObjectMain
	//no title card?
	Callfunction(Night_AI)

	if Object[5].Type == TypeName[Blank Object]

		if PlayerJumpscared == 0
			if Object[9].Type == TypeName[Blank Object]
				if inputpress.Start == true
					
					// Disable start for this frame, this'll help with "double-pausing" cases
					inputpress.Start = false
				
					// Give different pause menus depending on if the player was brought here from the Dev Menu
					// (...but why?)
			
					// Pause the stage, this'll pause all the stage's objects too
					Stage.State = STAGE_PAUSED
					
					// and pause the stage's music, as well
					PauseMusic()
					// Create the Pause Menu and set it up as needed
					Object[9].Type = TypeName[Pause Menu]
					Object[9].DrawOrder = 6
					Object[9].Priority = 2
				end if
			end if
		end if	



		switch object.state
		case 0
			if OfficePower <= 0
				object.state = 1
			end if	
		break
		case 1
				if Object.OuttaPower == 0
					CheckEqual(NightWon, 0)
					temp0 = checkResult
					CheckEqual(PlayerJumpscared, 0)
					temp0 &= checkResult		
					if temp0 == 1	
						Object.OuttaPower = 1
						ForcePull = 1
						FlashLocked = 1
						PlaySfx(SfxName[PowerOut], 0)
						StopMusic()
					end if
				end if
		
			
				StopSfx(SfxName[Fan])
				StopSfx(SfxName[Fan2])
				StopSfx(SfxName[Fan3])
		

			object.state++
		break
		case 2
			
		break
		end switch


			

		CallFunction(Office_PowerDraining)

		//Not using the camera?
		//Activate base office controls
		CheckEqual(CameraEnabled, 0)
		temp6 = checkResult
		CheckEqual(PlayerJumpscared, 0)
		temp6 &= checkResult	
		CheckEqual(NightWon, 0)
		temp6 &= checkResult
		if temp6 == 1

			//para android	touch rects
			CheckTouchRect(0, 0, screen.xsize, screen.ysize)
			if checkResult == -1
				Object.TouchTimer = false
			end if
			if Object.TouchTimer == 0


				temp0 = object.value0
				temp0 += 90
				temp1 = object.value0
				temp1 += 340
				CheckTouchRect(0, 130, screen.xsize, 200)
				if CheckResult > -1
					inputDown.buttonZ = 1
				end if		

				temp0 = object.value0
				temp0 += 95
				temp1 = object.value0
				temp1 += 335
				CheckTouchRect(temp0, 95, temp1, 130)
				if CheckResult > -1
					inputDown.buttonZ = 1
				end if						


				//LEFT BUTTONS
				if Object.ScrollPos > 100
					temp0 = object.value0
					temp0 += 42
					temp1 = object.value0
					temp1 += 88
					CheckTouchRect(temp0, 96, temp1, 128)
					if CheckResult > -1
						Object.TouchTimer = 1
						inputpress.buttona = 1
					end if
				end if

				//RIGHT BUTTONS
				Object.RightButtonPos = 530
				Object.RightButtonPos -= screen.xsize
				not(Object.RightButtonPos)
				if Object.ScrollPos < Object.RightButtonPos
					temp0 = object.value0
					temp0 += screen.xsize
					temp0 -= 80
					temp1 = object.value0
					temp1 += screen.xsize
					temp1 -= 35
					CheckTouchRect(temp0, 96, temp1, 128)
					if CheckResult > -1
						Object.TouchTimer = 1
						inputpress.buttonc = 1
					end if
				end if

				//dont move with screen for fixed position
				temp0 = object.value2
				temp0 += 150
				temp1 = object.value2
				temp1 += 200
				CheckTouchRect(temp0, 82, temp1, 92)
				if CheckResult > -1
					object.TouchTimer = true
					PlaySfx(SfxName[Honk], 0)
				end if


				//dont move with screen for fixed position
				temp0 = object.value2
				temp0 += 195
				temp1 = object.value2
				temp1 += 230
				CheckTouchRect(temp0, 55, temp1, 85)
				if CheckResult > -1
					object.TouchTimer = true
					inputpress.buttonX = 1
				end if

			end if

			//for when the camera is down
		
			
		
			//mouse controls

			//you scroll faster the farther you are on each side
			//based off mouse position on the xpos
			
			if saved.Mouse == 1
				UseMouse = 0
			else
				UseMouse = 1
			end if
			if UseMouse == 1
		
				if Object.ScrollPos < LEFTLIMIT
					if touchscreen[0].xpos < 170
						Object.ScrollPos += 3
					end if
				end if	
				if Object.ScrollPos < LEFTLIMIT
					if touchscreen[0].xpos < 120
						Object.ScrollPos += 5
					end if
				end if
				
				Object.RightLimit = 565
				Object.RightLimit -= screen.xsize
				not(Object.RightLimit)
				
			
				temp0 = screen.xcenter
				temp0 += 50
				if Object.ScrollPos > Object.RightLimit
					if touchscreen[0].xpos > temp0
						Object.ScrollPos -= 3
					end if
				end if
				temp0 = screen.xcenter
				temp0 += 90
				if Object.ScrollPos > Object.RightLimit
					if touchscreen[0].xpos > temp0
						Object.ScrollPos -= 5
					end if
				end if



			else	//manual controls if your like that ig


				Object.RightLimit = 565
				Object.RightLimit -= screen.xsize
				not(Object.RightLimit)
				if Object.ScrollPos > Object.RightLimit
					if inputdown.right == 1
						Object.ScrollPos -= 7
					end if
				end if

				if Object.ScrollPos < LEFTLIMIT
					if inputdown.left == 1
						Object.ScrollPos += 7
					end if
				end if				

				
					
				
			end if	
		end if

		CallFunction(Office_Controls)

		if object[30].type != TypeName[Blank Object]
			//dont move with screen for fixed position
			temp0 = 0
			temp1 = 100
			CheckTouchRect(temp0, 0, temp1, 30)
			if CheckResult > -1
				object.TouchTimer = true
				StopSfx(SfxName[Phone])
				object[30].type = TypeName[Blank Object]
			end if
		end if

		//bar
		if PlayerJumpscared == 0
			MaskMode = 1		
			if MaskMode == 0
				CheckTouchRect(0, 208, screen.xsize, 240)
				if CheckResult > -1
					Object.TouchTimer = 1
					inputpress.buttonB = 1
				end if
			else
				//camera
				temp0 = screen.xsize
				temp0 /= 2
				CheckTouchRect(0, 208, temp0, 240)
				if CheckResult > -1
					Object.TouchTimer = 1
					inputpress.buttonB = 1
				end if
				if CameraEnabled == 0
					temp0 = screen.xsize
					temp1 = screen.xcenter
					CheckTouchRect(temp1, 208, temp0, 240)
					if CheckResult > -1
						Object.TouchTimer = 1
						inputpress.buttonY = 1
					end if
				end if	
			end if
		end if
	end if
end event

event ObjectDraw

	//filler
	DrawRect(0, 0, Screen.XSize, Screen.YSize, 0, 0, 0, 255)

	DrawSpriteScreenXY(10, Object.ScrollPos, Object.OfficeAngle)
//

	if OfficePower <= 0
		CameraEnabled = 0
		LDoorLocked = 1
		RDoorLocked = 1
		MDoorLocked = 1
		LeftDoorClosed = 0
		RightDoorClosed = 0
		MiddleDoorClosed = 0		
		Object.LeftDoor = 0
		Object.RightDoor = 0	
		Object.MiddleDoor = 0	

		if Object.LeftLight == 1
			Object.RightLight = 0
		end if
		if Object.RightLight == 1
			Object.LeftLight = 0
		end if
	end if




//	temp0 = Object.ScrollPos
//	abs(temp0)
//	DrawNumbers(0, 32, 96, saveRAM[6017], 3, 8, 0)

end event


event ObjectStartup
	
	LoadSpriteSheet("FNAF/Objects.gif")
	
	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[2].Type = TypeName[Office]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[2].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[2].DrawOrder = 3

	Object[2].ScrollPos = 50

	LeftDoorClosed = 0
	RightDoorClosed = 0
	MiddleDoorClosed = 0
	UseMouse = 0
	OfficePower = 100
	CameraEnabled = 0
	PowerUsage = 1
	MaskMode = 0
	MaskEquipped = 0
	NightWon = 0

	LDoorLocked= 0
	RDoorLocked = 0
	MDoorLocked = 0

	LWindowScare= 0
	RWindowScare = 0

	PlayerJumpscared = 0
	ForcePull = 0
	OfficeScary = 0

	FlashlightOn = 0
	FlashLocked = 0

	SetMusicTrack("OfficeVibes.ogg", 0, 1)
	SetMusicTrack("OfficeLose.ogg", 1, 0)
	SetMusicTrack("BearWin.ogg", 2, 0)
	SetMusicTrack("JackInBox.ogg", 3, 94036)
	SetMusicTrack("OfficeTense.ogg", 4, 1)
	SetMusicTrack("ForeverRingtone.ogg", 5, 0)
	SetMusicTrack("bearwin2.ogg", 6, 0)
	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	//SpriteFrame(-115, -1, 556, 253, 1, 1) // 10 - office og

	SpriteFrame(-115, -56, 682, 426, 1, 509) // 10 - office

	// 11 - mice
	SpriteFrame(0, 0, 12, 21, 1011, 1)


	//Left

	// 12 - Left Buttons
	SpriteFrame(-72, 96, 33, 66, 684, 509)	

	// 13 - 14, Door Lit, Light Lit
	SpriteFrame(-72, 96, 33, 34, 719, 509)	
	SpriteFrame(-72, 128, 33, 34, 719, 541)	//loght	

	//15 left door lit empty
	SpriteFrame(-34, -1, 134, 327, 684, 643)

	//16 left door empty frame
	SpriteFrame(-34, -40, 95, 369, 565, 139)	
	//17 left door
	SpriteFrame(-27, -302, 84, 314, 661, 194)	


	//Right

	// 18 - right Buttons
	SpriteFrame(490, 96, 33, 66, 684, 576)	

	// 19 - 20, Door Lit, Light Lit
	SpriteFrame(490, 96, 33, 34, 719, 576)	
	SpriteFrame(490, 128, 33, 34, 719, 608)	//loght	

	//21 right door lit empty
	SpriteFrame(352, -1, 134, 327, 819, 643)

	//22 right door empty frame
	SpriteFrame(391, -40, 95, 369, 831, 139)	
	//23 right door
	SpriteFrame(395, -302, 84, 314, 746, 194)	

	//24 fan animation frames
	SpriteFrame(218, 122, 40, 48, 794, 509)	
	//25 
	SpriteFrame(218, 122, 40, 48, 753, 509)		
	
	//fred 26 
	SpriteFrame(440, 67, 42, 126, 954, 643)		
	//bun 27
	SpriteFrame(-33, 46, 125, 188, 244, 1)		
	//jockey 28
	SpriteFrame(352, 41, 41, 118, 954, 770)	
	//golden gang 29
	SpriteFrame(140, 41, 166, 169, 370, 1)	

	//spring trap eyes
	SpriteFrame(225, 46, 62, 34, 621, 936)		//30

	//Middle Door Overlay
	SpriteFrame(225, 12, 62, 76, 437, 935)		//31

	//MiddleDoor
	SpriteFrame(226, 1, 61, 39, 499, 936)		//32

	//buton mid
	SpriteFrame(201, -2, 23, 23, 302, 936)		//33
	SpriteFrame(201, -2, 23, 23, 326, 936)		//34


	//flash ig? lol
	SpriteFrame(-128,-128,256,256,1,252)	//35
end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
